package com.huluobo.a2109kotlinshopping

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
import com.blankj.utilcode.util.SPUtils
import com.huluobo.a2109kotlinshopping.base.BaseMVVMActivity
import com.huluobo.a2109kotlinshopping.databinding.ActivityMainBinding
import com.huluobo.a2109kotlinshopping.db.DatabaseUtil
import com.huluobo.a2109kotlinshopping.net.ApiService
import com.huluobo.a2109kotlinshopping.net.Const
import com.huluobo.a2109kotlinshopping.net.RetrofitManager
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers

/**
 * 使用Navigation搭建主页面,总结:
 * 1.在res下生成Navigation的文件夹,创建Navigation图表
 * 2.添加几个fragment在图表中
 * 3.创建menu,有几个fragment就写几个item,***********注意***********item的id必须和图表中的fragment的id一直,否则找不到对应的fragment
 * 4.在main的xml中拉出一个控件NavHostFragment,直接拉,需要修改标签为fragment
 * 5.给生成NavHostFragment添加刚刚生成的图表,也就是main_nav
 * 6,设置底部导航栏与导航控制器(图表)联动
 */
class MainActivity : BaseMVVMActivity<ActivityMainBinding>() {
    override fun initData() {
    }

    override fun initView() {
        //获取导航宿主fragment
        val navHostFragment = supportFragmentManager.findFragmentById(R.id.main_nav_host_fragment) as NavHostFragment
        //获取导航控制器
        val navController = navHostFragment.navController
        //给底部导航栏绑定导航器
        dataBinding.mainBottomNav.setupWithNavController(navController)

        val user = DatabaseUtil.getDb().userInfoDao().queryUserInfo(SPUtils.getInstance().getInt(Const.SP_ID))
        Log.i("TagA", "user:$user")
    }

    override fun getLayoutId(): Int = R.layout.activity_main
}